package bawei.com.fragment;

import android.os.Bundle;


import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;


import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



import com.squareup.okhttp.Request;


import com.squareup.okhttp.Response;


import java.util.List;


import bawei.com.adapter.RegionTypeDetailsAdapter;
import bawei.com.bilibili.R;



import bawei.com.model.BaseCallback;

import bawei.com.model.Network;
import bawei.com.model.OkHttpHelper;


import bawei.com.model.bean.RegionTypeDetailsBean;

/**
 * 类描述:
 * 作者：cwm
 * 时间:2017/3/21 19:16
 * 邮箱:18310832074@163.com
 */

public class RegionTypeDetailsFragment extends Fragment {



    private View view;


    private int rid;


    private RecyclerView recyclerView;


    public static RegionTypeDetailsFragment newInstance(int rid) {

        RegionTypeDetailsFragment fragment = new RegionTypeDetailsFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("rid", rid);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_region_details,null);
        recyclerView = (RecyclerView) view.findViewById(R.id.recycle);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        rid = getArguments().getInt("rid");
        getdate();
    }

    private void getdate() {


        OkHttpHelper.getinstance().get(Network.FQXQ + rid, new BaseCallback<RegionTypeDetailsBean>() {

            @Override
            public void onRequestBefore() {

            }

            @Override
            public void onFailure(Request request, Exception e) {

            }

            @Override
            public void onSuccess(Response response, RegionTypeDetailsBean regionTypeDetailsBean) {

                List<RegionTypeDetailsBean.DataBean.NewBean> newX = regionTypeDetailsBean.getData().getNewX();

                List<RegionTypeDetailsBean.DataBean.RecommendBean> recommend = regionTypeDetailsBean.getData().getRecommend();
                RegionTypeDetailsAdapter adapter=new RegionTypeDetailsAdapter(getActivity(),newX,recommend);
                recyclerView.setAdapter(adapter);


            }
            @Override
            public void onError(Response response, int errorCode, Exception e) {

            }
        });



    }


}
